<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>填写申请表</title>
    <link rel="stylesheet" href="../../css/element.css">
    <link rel="stylesheet" href="../../css/base.css">

    <style>

    </style>
</head>
<body class="frame-body">
<div id="wrapper" v-cloak>
    <el-row style="margin-bottom: 50px">
        <el-col :span="10" :offset="7">

            <div style="margin: 10px 0">
                <el-card>
                    <el-form :model="entity">
                        <el-form-item label="案号" label-width="120px">
                            <el-input v-model="entity.caseNum" autocomplete="off" style="width: 80%"></el-input>
                        </el-form-item>
                        <el-form-item label="案件标题" label-width="120px">
                            <el-input v-model="entity.caseTitle" autocomplete="off" style="width: 80%"></el-input>
                        </el-form-item>
                        <el-form-item label="案件描述" label-width="120px">
                            <el-input type="textarea" :rows="5"  v-model="entity.caseDescription" autocomplete="off" style="width: 80%;"></el-input>
                        </el-form-item>
                        <el-form-item label="案件类型" label-width="120px">
                            <el-select v-model="entity.caseType" placeholder="请选择" style="width: 80%">
                                <el-option label="刑事案件" value="刑事案件"></el-option>
                                <el-option label="民事案件" value="民事案件"></el-option>
                                <el-option label="行政案件" value="行政案件"></el-option>
                                <el-option label="商事案件" value="商事案件"></el-option>
                                <el-option label="家事案件" value="家事案件"></el-option>
                                <el-option label="劳动争议案件" value="劳动争议案件"></el-option>
                                <el-option label="知识产权案件" value="知识产权案件"></el-option>
                                <el-option label="离婚案件" value="离婚案件"></el-option>
                                <el-option label="财产纠纷案件" value="财产纠纷案件"></el-option>
                                <el-option label="交通事故案件" value="交通事故案件"></el-option>
                                <el-option label="其他" value="其他"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="案件地点" label-width="120px">
                            <el-input v-model="entity.caseLocation" autocomplete="off" style="width: 80%"></el-input>
                        </el-form-item>
                        <el-form-item label="附件上传" label-width="120px">
                            <div style="padding: 5px 0; text-align: center">
                                <el-upload
                                        class="avatar-uploader"
                                        action="/files/upload"
                                        :show-file-list="false"
                                        :on-success="handleAvatarSuccess">
                                    <img v-if="entity.supportingDocuments" :src="['/files/' + 'doc_icon.jpeg']"
                                         style="height: 100px;width: 100px;display: block" class="avatar">
                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                </el-upload>
                            </div>
                        </el-form-item>
                    </el-form>
                    <div style="text-align: center">
                        <el-button type="primary" @click="save">提交申请</el-button>
                    </div>
                </el-card>
            </div>

        </el-col>
    </el-row>



</div>

<!--    js-->
<script src="../../js/jquery.min.js"></script>

<script src="../../js/vue.min.js"></script>
<script src="../../js/element.js"></script>

<script>
    let urlBase = "/api/applications/";
    new Vue({
        el: "#wrapper",
        data: {
            user: {},
            entity:{},
        },
        created() {
            $.ajax({url: '/api/user/session', method: "GET", async: false, success: (res) => {this.user = res.data || {}}})
            this.loadTable()
        },
        methods: {
            handleAvatarSuccess(res) {
                this.entity = JSON.parse(JSON.stringify(this.entity))
                this.entity.supportingDocuments = res.data
            },
            logout() {
                $.get("/api/user/logout");
                sessionStorage.removeItem("user");
                location.href = "/page/end/login.html";
            },
            loadTable() {
                if(!this.user.id) {
                    this.$message({
                        message: "请登录！",
                        type: "warning"
                    })
                    return
                }
                $.get("/api/user/" + this.user.id).then(res => {
                    this.user = res.data
                })
            },
            save() {
                let type = this.entity.id ? "PUT" : "POST";
                $.ajax({
                    url: urlBase,
                    type: type,
                    contentType: "application/json",
                    data: JSON.stringify(this.entity)
                }).then(res => {
                    if (res.code === '0') {
                        this.$message({
                            message: "保存成功",
                            type: "success"
                        });
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        })
                    }
                    this.entity = {}
                })
            },
        }
    })
</script>
</body>
</html>
